package com.zzzyh.spring.controller;

import com.zzzyh.spring.pojo.Message;
import com.zzzyh.spring.service.MessagewallService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RequestMapping("/messagewall")
@RestController
public class MessagewallContriller {
    @Autowired
    public MessagewallService messagewallService;

    @RequestMapping("/getMessages")
    public List<Message> getMessage(){
        return messagewallService.getMessages();
    }

    @RequestMapping("/addMessage")
    public boolean addMessage(Message message){
        if(!StringUtils.hasLength(message.to) || !StringUtils.hasLength(message.from) || !StringUtils.hasLength(message.message))
            return false;

        return messagewallService.addMessage(message);
    }
}
